<template>
  <div class="hello">
    <h1>{{ msg }}</h1>
    <h2>Essential Links</h2>
    <h2>{{token}}</h2>
    <div>
      <button @click="get">封装的get</button>
      <button @click="post">封装的post</button>
    </div>
  </div>
</template>

<script>
import {getSubject, login} from '@/api/index'
export default {
  name: 'HelloWorld',
  data () {
    return {
      msg: 'Welcome to Your Vue.js App',
      token: ''
    }
  },
  created () {
    this.getToken()
  },
  methods: {
    get () {
      console.log('get is done')
      getSubject({path: 'study'}).then(res => {
        console.log('res', res)
      })
    },
    post () {
      console.log('post is done')
      let obj = {
        name: 'lxy',
        age: 18
      }
      login(obj).then(res => {
        console.log('res', res.data)
      })
    },
    getToken () {
      this.token = this.$store.state.token
      console.log('当前用户标识', this.token)
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
h1, h2 {
  font-weight: normal;
}
ul {
  list-style-type: none;
  padding: 0;
}
li {
  display: inline-block;
  margin: 0 10px;
}
a {
  color: #42b983;
}
</style>
